package com.android.sharecar.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.android.sharecar.model.User;

/**
 * class:SignupStep3Activity
 *  Deals with the signup transactions,
 *  include user's car info
 * date:	2011-9-7
 * @author xinyan
 * 
 */
public class SignupStep3Activity extends Activity {
	public static final String TAG = "SignupStep3Activity";

	private EditText mCarStyle; // var for car style edit text
	private EditText mCarId; // var for car id edit text
	private EditText mCarColor; // var for car color spinner
	private Button mSubmitCarInfo; // var for signup finish button

	public static User user;

	// constants
	public static final String ALERT_TYPE_EMPTY = "not input";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.signup3);

		mCarColor = (EditText) findViewById(R.id.signup_et_carColor);
		mCarId = (EditText) findViewById(R.id.signup_et_carId);
		mCarStyle = (EditText) findViewById(R.id.signup_et_carStyle);
		mSubmitCarInfo = (Button) findViewById(R.id.signup_btn_submitCarInfo);

		mSubmitCarInfo.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				String strCarColor = mCarColor.getText().toString();
				String strCarId = mCarId.getText().toString();
				String strCarStyle = mCarStyle.getText().toString();

				if ("" == strCarColor || "" == strCarId || "" == strCarStyle) {
					AlertDialog alertEmpty = creatBuilder(ALERT_TYPE_EMPTY)
							.create();
					alertEmpty.show();

					return;
				} else { // else user finish the input
					user = new User();

					user.setCarId(strCarId);
					user.setCarStyle(strCarStyle);
					user.setColor(strCarColor);

					// uploadCarInfo(user);
					// these connection method should put in a conn class.
				}

			}

		});
	}

	/**
	 * Builder creator
	 * used for create all kinds of warning dialog in this
	 * activity
	 * 
	 * @param type
	 *            alert type, constants listed on the top area.
	 * @return return a builder
	 */
	private AlertDialog.Builder creatBuilder(String type) {
		AlertDialog.Builder builder = new AlertDialog.Builder(
				SignupStep3Activity.this);
		builder.setTitle("警告");
		if (ALERT_TYPE_EMPTY == type) {
			builder.setMessage("请您输入完整的注册信息！");
		}

		builder.setPositiveButton("确定", null);

		return builder;
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

}
